//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.doc.controller;

import com.farm.core.page.RequestMode;
import com.farm.core.page.ViewMode;
import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.result.DataResult;
import com.farm.doc.server.FarmDocIndexInter;
import com.farm.doc.server.FarmDocManagerInter;
import com.farm.doc.server.FarmDocOperateRightInter;
import com.farm.doc.server.FarmDocTypeInter;
import com.farm.doc.server.FarmDocgroupManagerInter;
import com.farm.doc.server.utils.IndexUtils;
import com.farm.doc.server.utils.IndexUtilsDomain;
import com.farm.web.WebUtils;
import com.farm.web.easyui.EasyUiUtils;
import java.util.Date;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@RequestMapping({"/lucene"})
@Controller
public class ActionFarmLuceneQuery extends WebUtils {
    @Resource
    private FarmDocManagerInter farmDocManagerImpl;
    @Resource
    private FarmDocOperateRightInter farmDocOperateRightImpl;
    @Resource
    private FarmDocgroupManagerInter farmDocgroupManagerImpl;
    @Resource
    private FarmDocIndexInter farmDocIndexManagerImpl;
    @Resource
    private FarmDocTypeInter farmDocTypeManagerImpl;
    private String taskKey;
    private static final Logger log = Logger.getLogger(ActionFarmLuceneQuery.class);

    public ActionFarmLuceneQuery() {
    }

    @RequestMapping({"/query"})
    @ResponseBody
    public Map<String, Object> queryall(DataQuery query, HttpServletRequest request) {
        try {
            query = EasyUiUtils.formatGridQuery(request, query);
            DataResult result = this.farmDocManagerImpl.createSimpleDocQuery(query).addRule(new DBRule("DOMTYPE", "4", "!=")).search();
            result.runDictionary("1:开放,0:禁用,2:待审核", "STATE");
            result.runDictionary("1:知识文档,5:资源文件,2:TXT", "DOMTYPE");
            result.runDictionary("1:分类,0:本人,2:小组,3:禁止", "WRITEPOP");
            result.runDictionary("1:分类,0:本人,2:小组,3:禁止", "READPOP");
            result.runformatTime("PUBTIME", "yyyy-MM-dd HH:mm:ss");
            return ViewMode.getInstance().putAttrs(EasyUiUtils.formatGridData(result)).returnObjMode();
        } catch (Exception var4) {
            log.error(var4.getMessage());
            return ViewMode.getInstance().setError(var4.getMessage()).returnObjMode();
        }
    }

    @RequestMapping({"/reIndex"})
    @ResponseBody
    public Map<String, Object> reIndex(DataQuery query, HttpServletRequest request) {
        try {
            IndexUtilsDomain state = IndexUtils.getTaskState(this.taskKey);
            if (state.getState() == 3 || state.getState() == -1) {
                state = IndexUtils.startReKnowIndexTaskBy((new Date()).toString(), query, this.farmDocManagerImpl, this.farmDocIndexManagerImpl);
                this.taskKey = state.getTaskKey();
            }

            return ViewMode.getInstance().putAttr("task", state).returnObjMode();
        } catch (Exception var4) {
            log.error(var4.getMessage());
            return ViewMode.getInstance().setError(var4.getMessage()).returnObjMode();
        }
    }

    @RequestMapping({"/delForm"})
    public ModelAndView delForm(RequestMode pageset, String ids) {
        return ViewMode.getInstance().putAttr("pageset", pageset).returnModelAndView("doc/DocIndexForm");
    }

    @RequestMapping({"/delCommit"})
    @ResponseBody
    public Map<String, Object> delCommit(HttpSession session, String indexid) {
        try {
            this.farmDocIndexManagerImpl.delLuceneIndex(indexid);
            return ViewMode.getInstance().returnObjMode();
        } catch (Exception var4) {
            var4.printStackTrace();
            return ViewMode.getInstance().setError(var4.getMessage()).returnObjMode();
        }
    }

    @RequestMapping({"/indexPersont"})
    @ResponseBody
    public Map<String, Object> loadIndexStatr() {
        return ViewMode.getInstance().putAttr("task", IndexUtils.getTaskState(this.taskKey)).returnObjMode();
    }
}
